package web.simulation.memento;

import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


@RestController  
@RequestMapping("/memento") 
public class mementoClient {
	@RequestMapping("/{type}")  
    public Object view(@PathVariable("type") Integer type) {
		
		OperationApi operation = new Operation();
		
		AddCommand addCmd = new AddCommand(type+2);
		SubCommand substractCmd = new SubCommand(type);
		 
		addCmd.setOperation(operation);
		substractCmd.setOperation(operation); 
		 
		Calculator calculator = new Calculator();
		calculator.setAddCmd(addCmd);
		calculator.setSubstractCmd(substractCmd);
		
		 
		calculator.addPressed();
		System.out.println("增"+operation.getResult());
		calculator.substractPressed();
		System.out.println("减"+operation.getResult());
		
		 
		calculator.undoPressed();
		System.out.println("恢复1"+operation.getResult());
		calculator.undoPressed();
		System.out.println("恢复2"+operation.getResult());
		
		 
		calculator.redoPressed();
		System.out.println("重新"+operation.getResult());
		calculator.redoPressed();
		System.out.println("excuet"+operation.getResult());
        return "成功!";  
    }  
}